<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Partner extends Model
{
    use SoftDeletes;
	//指定表名
	protected $table='partner';
	//指定id
	protected $primaryKey ='id';
    // 日期都存储为时间戳
    protected $dateFormat = 'U';

    static protected $typeArray = [
        1 => '自媒体',
        2  => '咖啡馆'
    ];

	//批量赋值
	public function cafes(){
		return $this->belongsToMany('App\Cafe','cafe_partner','partner_id','cafe_id');
	}
	public function info(){
		return $this->hasOne('App\Users','id','user_id');
	}
 	public function users()
	{
		return $this->belongsToMany('App\Users','user_partners','partner_id','user_id');
	}
	public function menus(){
	    return $this->hasMany('App\Menus','partner_id','');
    }

    public function weixinArticle()
    {
        return $this->hasMany('App\WechatArticle', 'weixin_article', 'weixin_name', 'weixin_name');
    }

    // 追加type_text字段,type的文本类型
    public function getTypeTextAttribute()
    {
        return self::$typeArray[$this->attributes['type']];
    }
}
